package water.com.Aop;

import water.com.Service.base.BaseCore;
import water.com.Service.entity.In.BaseIn;
import water.com.Service.entity.Out.BaseOut;
import water.com.util.Built;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 接口切面，用于处理接口处理的功能增强
 */
public class WaterOutHandler implements InvocationHandler {

    private BaseCore<BaseIn,BaseOut> target;

    public WaterOutHandler(BaseCore<BaseIn,BaseOut> target){
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        BaseOut res = null;
        res = (BaseOut) method.invoke(target,args);

        //为每一次请求成功增加唯一流水号
        if(res!=null){
            res.getSysHead().setReference(Built.getReference(res.getClass().getSimpleName()));
        }

        return res;
    }


}
